package lueerror

import (
	"errors"
	"net/http"
)

// UnhandledErr 未捕捉错误
func UnhandledErr(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusInternalServerError,
		code:       "50000",
		error:      err,
		alert:      "服务器开小差了~",
		sendMail:   true,
	}
}

// InvalidRequest 请求参数错误
func InvalidRequest(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40001",
		error:      err,
		alert:      "参数错误",
		sendMail:   false,
	}
}

// PgErr mysql 异常
func PgErr(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusInternalServerError,
		code:       "50001",
		error:      err,
		alert:      "服务器开小差了~",
		sendMail:   true,
	}
}

// RedisErr redis 异常
func RedisErr(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusInternalServerError,
		code:       "50002",
		error:      err,
		alert:      "服务器开小差了~",
		sendMail:   true,
	}
}

// MqErr 消息中间件异常
func MqErr(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusInternalServerError,
		code:       "50003",
		error:      err,
		alert:      "服务器开小差了~",
		sendMail:   true,
	}
}

// GrpcErr grpc 异常
func GrpcErr(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusInternalServerError,
		code:       "50004",
		error:      err,
		alert:      "服务器开小差了~",
		sendMail:   true,
	}
}

// MobileHasUsed 手机号已经使用
func MobileHasUsed(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusNotAcceptable,
		code:       "40002",
		error:      err,
		alert:      "手机号已经被使用",
		sendMail:   false,
	}
}

// AccNotExit 账号不存在
func AccNotExit(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusNotFound,
		code:       "40004",
		error:      err,
		alert:      "用户不存在",
		sendMail:   false,
	}
}

// InvalidPassword 登陆认证失败
func InvalidPassword(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusUnauthorized,
		code:       "40005",
		error:      err,
		alert:      "请出入正确的密码",
		sendMail:   false,
	}
}

// EmailHasUsed 邮箱已经使用
func EmailHasUsed(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusNotAcceptable,
		code:       "40006",
		error:      err,
		alert:      "邮件已经被使用",
		sendMail:   false,
	}
}

// CodeVerifyFailed 验证码验证失败
func CodeVerifyFailed(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusUnauthorized,
		code:       "40007",
		error:      err,
		alert:      "验证失败",
		sendMail:   false,
	}
}

// AuthGrantErr 授权失败
func AuthGrantErr(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusUnauthorized,
		code:       "40008",
		error:      err,
		alert:      "授权失败",
		sendMail:   false,
	}
}

// PreventLogin 登陆错误
func PreventLogin(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusUnauthorized,
		code:       "40009",
		error:      err,
		alert:      "登陆失败",
		sendMail:   false,
	}
}

// InvalidMobile 手机号错误
func InvalidMobile(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40010",
		error:      err,
		alert:      "手机号格式错误",
		sendMail:   false,
	}
}

// InvalidEmail 邮箱格式错误
func InvalidEmail(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40011",
		error:      err,
		alert:      "邮箱格式错误",
		sendMail:   false,
	}
}

// MobileEmailHasUsed 手机号或邮箱已经被使用
func MobileEmailHasUsed() LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40012",
		error:      errors.New("手机号或邮箱已经被使用"),
		alert:      "请确认手机号是否已经使用",
		sendMail:   false,
	}
}

// InvalidChannel 渠道信息异常
func InvalidChannel(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40012",
		error:      err,
		alert:      "渠道信息异常",
		sendMail:   false,
	}
}
